package com.cjl.dental_clinic.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cjl.dental_clinic.base.BaseController;
import com.cjl.dental_clinic.base.ResVo;
import com.cjl.dental_clinic.entity.Medicalequipment;
import com.cjl.dental_clinic.service.MedicalequipmentService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: cjl
 * @time: 2024/03/28 11:20
 */
@RestController
@RequestMapping ("cjl/medicalequipment")
public class MedicalequipmentController extends BaseController<Medicalequipment, MedicalequipmentService> {
    public MedicalequipmentController(MedicalequipmentService baseService) {
        super(baseService);
    }

    @PostMapping("list")
    public ResVo<List<Medicalequipment>> list(String name){
        if (!StringUtils.hasText(name)) {
            return ResVo.ok("查询成功",baseService.list());
        }
        QueryWrapper<Medicalequipment> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name",name);
        return ResVo.ok("查询成功",baseService.list(queryWrapper));
    }


    @PostMapping("update")
    public ResVo<Boolean> upDate(Medicalequipment medicalequipment){
        System.out.println(medicalequipment.toString());
        if (medicalequipment.getStatus()==2) {
            medicalequipment.setCleartime(new Date());
        }
        return ResVo.ok(baseService.updateById(medicalequipment));
    }

    @PostMapping("del")
    public ResVo<Boolean> del(Integer id){
        return ResVo.ok(baseService.removeById(id));
    }
}
